<?php

namespace App\Admin\Controllers;

use App\Models\GrGood;
use App\Models\GrGoodsType;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class UserTable extends LazyRenderable
{
    public function grid(): Grid
    {
        // 获取外部传递的参数
        return Grid::make(new GrGood(), function (Grid $grid) {
            $grid->column('goods_id');
            $grid->column('goods_name');
            $grid->column('stock_total','库存');
            $grid->column('goods_now_price','商品实际价格');
            $grid->column('goods_img_cover')->image('',100,100);
            $grid->column('goods_type_id')->display(function ($e){
                 $data=GrGoodsType::where('goods_type_id',$this->goods_type_id)->pluck('goods_type_name');
                 return $data[0];
            });
            $grid->column('created_at');
            $grid->column('updated_at')->display(function (){
            });

            // 指定行选择器选中时显示的值的字段名称
            // 指定行选择器选中时显示的值的字段名称
            // 指定行选择器选中时显示的值的字段名称
            // 如果表格数据中带有 “name”、“title”或“username”字段，则可以不用设置
            $grid->rowSelector()->titleColumn('goods_name');

            $grid->quickSearch(['goods_name', 'is_grounding', 'goods_type']);

            $grid->paginate(9);
            $grid->disableActions();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('username')->width(4);
                $filter->like('name')->width(4);
            });
        });
    }
}
